<?php

class MappableWorkflowContainerDecorator extends AbstractWorkflowContainer
{
  
  /**
   * @var AbstractWorkflowContainer
   */
  protected $container;
  
  /**
   * @var array
   */
  protected $mappings = array();

  public function __construct (AbstractWorkflowContainer $container=null)
  {
    $this->container = $container;
  }

  /**
   * @param string $key
   * @return bool
   */
  public function isMapped ($key)
  {
    return isset($this->mappings[$key]);
  }

  /**
   * @param string $src_key
   * @param string $target_key
   */
  public function map ($src_key, $target_key)
  {
    $this->mappings[$target_key] = $src_key;
  }

  /**
   * @param string $key
   * @param mixed $default
   * @return mixed
   */
  public function getValue ($key, $default = null)
  {
    if ($this->isMapped($key))
    {
      return $this->container->getValue($this->mappings[$key], $default);
    }
    else
    {
      return $this->container->getValue($key, $default);
    }
  }

  /**
   * @param string $key
   * @param mixed $value
   */
  public function setValue ($key, $value)
  {
    $this->container->setValue($key, $value);
  }

  /**
   * @param string $key
   * @return bool
   */
  public function hasValue ($key)
  {
    return $this->container->hasValue($key) || $this->isMapped($key);
  }

  /**
   * @param AbstractWorkflowContainer $container
   */
  public function setContainer (AbstractWorkflowContainer $container)
  {
    $this->container = $container;
  }
}